﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace ChoViet.Lib.Common
{
	public class UserState
	{
		public static object getUserStateFromRequest(string key, string request, object defaultValue)
		{
			var oldState = HttpContext.Current.Session[key];
			var curentState = (oldState != null && oldState.ToString() != "") ? oldState.ToString() : defaultValue.ToString();
			var newState = HttpContext.Current.Request[request];

			// Save the new value only if it was set in this request
			if (newState != null)
			{
				HttpContext.Current.Session[key] = newState;
			} else {
				newState = curentState;
			}

			return newState != "" ? newState : defaultValue;
		}
	}
}
